// META: title=test WebNN API hardSigmoid operation
// META: global=window,dedicatedworker
// META: variant=?cpu
// META: variant=?gpu
// META: variant=?npu
// META: script=../resources/utils.js
// META: timeout=long

'use strict';

// https://www.w3.org/TR/webnn/#api-mlgraphbuilder-hard-sigmoid
// Calculate the non-smooth hard sigmoid function on the input tensor, used
// instead of the sigmoid function for faster computation.
//
// dictionary MLHardSigmoidOptions {
//   double alpha = 0.2;
//   double beta = 0.5;
// };
//
// MLOperand hardSigmoid(
//     MLOperand input, optional MLHardSigmoidOptions options = {});


const getHardSigmoidPrecisionTolerance = (graphResources) => {
  const toleranceValueDict = {float32: 2, float16: 2};
  const expectedDataType =
      getExpectedDataTypeOfSingleOutput(graphResources.expectedOutputs);
  return {metricType: 'ULP', value: toleranceValueDict[expectedDataType]};
};

const hardSigmoidTests = [
  {
    'name': 'hardSigmoid float32 positive 1D constant tensor default options',
    'graph': {
      'inputs': {
        'hardSigmoidInput': {
          'data': [
            0.05907066911458969, 0.7076089382171631, 0.5228404998779297,
            0.4231015741825104,  0.6643692851066589, 0.950294017791748,
            0.10918906331062317, 0.0129771139472723, 0.4755297303199768,
            0.5322551727294922,  0.684307873249054,  0.4662107527256012,
            0.3048996329307556,  0.8025872707366943, 0.2485964000225067,
            0.663689911365509,   0.5547611713409424, 0.554258406162262,
            0.7311381697654724,  0.4880960285663605, 0.7766845226287842,
            0.8455570340156555,  0.555302083492279,  0.5603444576263428
          ],
          'descriptor': {'dimensions': [24], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'hardSigmoid',
        'arguments': [{'input': 'hardSigmoidInput'}],
        'outputs': 'hardSigmoidOutput'
      }],
      'expectedOutputs': {
        'hardSigmoidOutput': {
          'data': [
            0.5118141174316406, 0.6415218114852905, 0.6045681238174438,
            0.5846202969551086, 0.6328738331794739, 0.6900588274002075,
            0.5218378305435181, 0.5025954246520996, 0.5951059460639954,
            0.6064510345458984, 0.6368615627288818, 0.5932421684265137,
            0.5609799027442932, 0.6605174541473389, 0.5497192740440369,
            0.6327379941940308, 0.6109522581100464, 0.6108517050743103,
            0.6462276577949524, 0.5976191759109497, 0.6553369164466858,
            0.669111430644989,  0.6110604405403137, 0.6120688915252686
          ],
          'descriptor': {'dimensions': [24], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name': 'hardSigmoid float32 positive 1D tensor default options',
    'graph': {
      'inputs': {
        'hardSigmoidInput': {
          'data': [
            0.05907066911458969, 0.7076089382171631, 0.5228404998779297,
            0.4231015741825104,  0.6643692851066589, 0.950294017791748,
            0.10918906331062317, 0.0129771139472723, 0.4755297303199768,
            0.5322551727294922,  0.684307873249054,  0.4662107527256012,
            0.3048996329307556,  0.8025872707366943, 0.2485964000225067,
            0.663689911365509,   0.5547611713409424, 0.554258406162262,
            0.7311381697654724,  0.4880960285663605, 0.7766845226287842,
            0.8455570340156555,  0.555302083492279,  0.5603444576263428
          ],
          'descriptor': {'dimensions': [24], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'hardSigmoid',
        'arguments': [{'input': 'hardSigmoidInput'}],
        'outputs': 'hardSigmoidOutput'
      }],
      'expectedOutputs': {
        'hardSigmoidOutput': {
          'data': [
            0.5118141174316406, 0.6415218114852905, 0.6045681238174438,
            0.5846202969551086, 0.6328738331794739, 0.6900588274002075,
            0.5218378305435181, 0.5025954246520996, 0.5951059460639954,
            0.6064510345458984, 0.6368615627288818, 0.5932421684265137,
            0.5609799027442932, 0.6605174541473389, 0.5497192740440369,
            0.6327379941940308, 0.6109522581100464, 0.6108517050743103,
            0.6462276577949524, 0.5976191759109497, 0.6553369164466858,
            0.669111430644989,  0.6110604405403137, 0.6120688915252686
          ],
          'descriptor': {'dimensions': [24], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name': 'hardSigmoid float32 positive 2D tensor default options',
    'graph': {
      'inputs': {
        'hardSigmoidInput': {
          'data': [
            0.05907066911458969, 0.7076089382171631, 0.5228404998779297,
            0.4231015741825104,  0.6643692851066589, 0.950294017791748,
            0.10918906331062317, 0.0129771139472723, 0.4755297303199768,
            0.5322551727294922,  0.684307873249054,  0.4662107527256012,
            0.3048996329307556,  0.8025872707366943, 0.2485964000225067,
            0.663689911365509,   0.5547611713409424, 0.554258406162262,
            0.7311381697654724,  0.4880960285663605, 0.7766845226287842,
            0.8455570340156555,  0.555302083492279,  0.5603444576263428
          ],
          'descriptor': {'dimensions': [4, 6], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'hardSigmoid',
        'arguments': [{'input': 'hardSigmoidInput'}],
        'outputs': 'hardSigmoidOutput'
      }],
      'expectedOutputs': {
        'hardSigmoidOutput': {
          'data': [
            0.5118141174316406, 0.6415218114852905, 0.6045681238174438,
            0.5846202969551086, 0.6328738331794739, 0.6900588274002075,
            0.5218378305435181, 0.5025954246520996, 0.5951059460639954,
            0.6064510345458984, 0.6368615627288818, 0.5932421684265137,
            0.5609799027442932, 0.6605174541473389, 0.5497192740440369,
            0.6327379941940308, 0.6109522581100464, 0.6108517050743103,
            0.6462276577949524, 0.5976191759109497, 0.6553369164466858,
            0.669111430644989,  0.6110604405403137, 0.6120688915252686
          ],
          'descriptor': {'dimensions': [4, 6], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name': 'hardSigmoid float32 positive 3D tensor default options',
    'graph': {
      'inputs': {
        'hardSigmoidInput': {
          'data': [
            0.05907066911458969, 0.7076089382171631, 0.5228404998779297,
            0.4231015741825104,  0.6643692851066589, 0.950294017791748,
            0.10918906331062317, 0.0129771139472723, 0.4755297303199768,
            0.5322551727294922,  0.684307873249054,  0.4662107527256012,
            0.3048996329307556,  0.8025872707366943, 0.2485964000225067,
            0.663689911365509,   0.5547611713409424, 0.554258406162262,
            0.7311381697654724,  0.4880960285663605, 0.7766845226287842,
            0.8455570340156555,  0.555302083492279,  0.5603444576263428
          ],
          'descriptor': {'dimensions': [2, 3, 4], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'hardSigmoid',
        'arguments': [{'input': 'hardSigmoidInput'}],
        'outputs': 'hardSigmoidOutput'
      }],
      'expectedOutputs': {
        'hardSigmoidOutput': {
          'data': [
            0.5118141174316406, 0.6415218114852905, 0.6045681238174438,
            0.5846202969551086, 0.6328738331794739, 0.6900588274002075,
            0.5218378305435181, 0.5025954246520996, 0.5951059460639954,
            0.6064510345458984, 0.6368615627288818, 0.5932421684265137,
            0.5609799027442932, 0.6605174541473389, 0.5497192740440369,
            0.6327379941940308, 0.6109522581100464, 0.6108517050743103,
            0.6462276577949524, 0.5976191759109497, 0.6553369164466858,
            0.669111430644989,  0.6110604405403137, 0.6120688915252686
          ],
          'descriptor': {'dimensions': [2, 3, 4], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name': 'hardSigmoid float32 positive 4D tensor default options',
    'graph': {
      'inputs': {
        'hardSigmoidInput': {
          'data': [
            0.05907066911458969, 0.7076089382171631, 0.5228404998779297,
            0.4231015741825104,  0.6643692851066589, 0.950294017791748,
            0.10918906331062317, 0.0129771139472723, 0.4755297303199768,
            0.5322551727294922,  0.684307873249054,  0.4662107527256012,
            0.3048996329307556,  0.8025872707366943, 0.2485964000225067,
            0.663689911365509,   0.5547611713409424, 0.554258406162262,
            0.7311381697654724,  0.4880960285663605, 0.7766845226287842,
            0.8455570340156555,  0.555302083492279,  0.5603444576263428
          ],
          'descriptor': {'dimensions': [1, 2, 3, 4], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'hardSigmoid',
        'arguments': [{'input': 'hardSigmoidInput'}],
        'outputs': 'hardSigmoidOutput'
      }],
      'expectedOutputs': {
        'hardSigmoidOutput': {
          'data': [
            0.5118141174316406, 0.6415218114852905, 0.6045681238174438,
            0.5846202969551086, 0.6328738331794739, 0.6900588274002075,
            0.5218378305435181, 0.5025954246520996, 0.5951059460639954,
            0.6064510345458984, 0.6368615627288818, 0.5932421684265137,
            0.5609799027442932, 0.6605174541473389, 0.5497192740440369,
            0.6327379941940308, 0.6109522581100464, 0.6108517050743103,
            0.6462276577949524, 0.5976191759109497, 0.6553369164466858,
            0.669111430644989,  0.6110604405403137, 0.6120688915252686
          ],
          'descriptor': {'dimensions': [1, 2, 3, 4], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name': 'hardSigmoid float32 positive 5D tensor default options',
    'graph': {
      'inputs': {
        'hardSigmoidInput': {
          'data': [
            0.05907066911458969, 0.7076089382171631, 0.5228404998779297,
            0.4231015741825104,  0.6643692851066589, 0.950294017791748,
            0.10918906331062317, 0.0129771139472723, 0.4755297303199768,
            0.5322551727294922,  0.684307873249054,  0.4662107527256012,
            0.3048996329307556,  0.8025872707366943, 0.2485964000225067,
            0.663689911365509,   0.5547611713409424, 0.554258406162262,
            0.7311381697654724,  0.4880960285663605, 0.7766845226287842,
            0.8455570340156555,  0.555302083492279,  0.5603444576263428
          ],
          'descriptor': {'dimensions': [1, 2, 1, 3, 4], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'hardSigmoid',
        'arguments': [{'input': 'hardSigmoidInput'}],
        'outputs': 'hardSigmoidOutput'
      }],
      'expectedOutputs': {
        'hardSigmoidOutput': {
          'data': [
            0.5118141174316406, 0.6415218114852905, 0.6045681238174438,
            0.5846202969551086, 0.6328738331794739, 0.6900588274002075,
            0.5218378305435181, 0.5025954246520996, 0.5951059460639954,
            0.6064510345458984, 0.6368615627288818, 0.5932421684265137,
            0.5609799027442932, 0.6605174541473389, 0.5497192740440369,
            0.6327379941940308, 0.6109522581100464, 0.6108517050743103,
            0.6462276577949524, 0.5976191759109497, 0.6553369164466858,
            0.669111430644989,  0.6110604405403137, 0.6120688915252686
          ],
          'descriptor': {'dimensions': [1, 2, 1, 3, 4], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name':
        'hardSigmoid float32 positive 4D tensor specified positive options.alpha default options.beta',
    'graph': {
      'inputs': {
        'hardSigmoidInput': {
          'data': [
            0.05907066911458969, 0.7076089382171631, 0.5228404998779297,
            0.4231015741825104,  0.6643692851066589, 0.950294017791748,
            0.10918906331062317, 0.0129771139472723, 0.4755297303199768,
            0.5322551727294922,  0.684307873249054,  0.4662107527256012,
            0.3048996329307556,  0.8025872707366943, 0.2485964000225067,
            0.663689911365509,   0.5547611713409424, 0.554258406162262,
            0.7311381697654724,  0.4880960285663605, 0.7766845226287842,
            0.8455570340156555,  0.555302083492279,  0.5603444576263428
          ],
          'descriptor': {'dimensions': [1, 2, 3, 4], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'hardSigmoid',
        'arguments': [
          {'input': 'hardSigmoidInput'},
          {'options': {'alpha': 0.7854232544278235}}
        ],
        'outputs': 'hardSigmoidOutput'
      }],
      'expectedOutputs': {
        'hardSigmoidOutput': {
          'data': [
            0.546395480632782,
            1,
            0.9106510877609253,
            0.8323138356208801,
            1,
            1,
            0.5857596397399902,
            0.5101925134658813,
            0.8734921216964722,
            0.9180455803871155,
            1,
            0.8661727905273438,
            0.7394752502441406,
            1,
            0.6952533721923828,
            1,
            0.9357223510742188,
            0.9353274703025818,
            1,
            0.8833619952201843,
            1,
            1,
            0.936147153377533,
            0.9401075839996338
          ],
          'descriptor': {'dimensions': [1, 2, 3, 4], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name':
        'hardSigmoid float32 negative 4D tensor specified negative options.alpha default options.beta',
    'graph': {
      'inputs': {
        'hardSigmoidInput': {
          'data': [
            -0.05907066911458969, -0.7076089382171631, -0.5228404998779297,
            -0.4231015741825104,  -0.6643692851066589, -0.950294017791748,
            -0.10918906331062317, -0.0129771139472723, -0.4755297303199768,
            -0.5322551727294922,  -0.684307873249054,  -0.4662107527256012,
            -0.3048996329307556,  -0.8025872707366943, -0.2485964000225067,
            -0.663689911365509,   -0.5547611713409424, -0.554258406162262,
            -0.7311381697654724,  -0.4880960285663605, -0.7766845226287842,
            -0.8455570340156555,  -0.555302083492279,  -0.5603444576263428
          ],
          'descriptor': {'dimensions': [1, 2, 3, 4], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'hardSigmoid',
        'arguments': [
          {'input': 'hardSigmoidInput'},
          {'options': {'alpha': -0.7854232544278235}}
        ],
        'outputs': 'hardSigmoidOutput'
      }],
      'expectedOutputs': {
        'hardSigmoidOutput': {
          'data': [
            0.546395480632782,
            1,
            0.9106510877609253,
            0.8323138356208801,
            1,
            1,
            0.5857596397399902,
            0.5101925134658813,
            0.8734921216964722,
            0.9180455803871155,
            1,
            0.8661727905273438,
            0.7394752502441406,
            1,
            0.6952533721923828,
            1,
            0.9357223510742188,
            0.9353274703025818,
            1,
            0.8833619952201843,
            1,
            1,
            0.936147153377533,
            0.9401075839996338
          ],
          'descriptor': {'dimensions': [1, 2, 3, 4], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name':
        'hardSigmoid float32 positive 4D tensor specified positive options.beta default options.alpha',
    'graph': {
      'inputs': {
        'hardSigmoidInput': {
          'data': [
            0.05907066911458969, 0.7076089382171631, 0.5228404998779297,
            0.4231015741825104,  0.6643692851066589, 0.950294017791748,
            0.10918906331062317, 0.0129771139472723, 0.4755297303199768,
            0.5322551727294922,  0.684307873249054,  0.4662107527256012,
            0.3048996329307556,  0.8025872707366943, 0.2485964000225067,
            0.663689911365509,   0.5547611713409424, 0.554258406162262,
            0.7311381697654724,  0.4880960285663605, 0.7766845226287842,
            0.8455570340156555,  0.555302083492279,  0.5603444576263428
          ],
          'descriptor': {'dimensions': [1, 2, 3, 4], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'hardSigmoid',
        'arguments': [
          {'input': 'hardSigmoidInput'},
          {'options': {'beta': 0.4361860418530341}}
        ],
        'outputs': 'hardSigmoidOutput'
      }],
      'expectedOutputs': {
        'hardSigmoidOutput': {
          'data': [
            0.4480001926422119, 0.577707827091217,  0.5407541394233704,
            0.5208063721656799, 0.5690599083900452, 0.626244843006134,
            0.4580238461494446, 0.4387814700603485, 0.5312919616699219,
            0.5426371097564697, 0.5730476379394531, 0.5294281840324402,
            0.4971659779548645, 0.5967035293579102, 0.48590531945228577,
            0.5689240097999573, 0.5471382737159729, 0.5470377206802368,
            0.5824136734008789, 0.533805251121521,  0.5915229320526123,
            0.6052974462509155, 0.5472464561462402, 0.5482549667358398
          ],
          'descriptor': {'dimensions': [1, 2, 3, 4], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name':
        'hardSigmoid float32 negative 4D tensor specified negative options.beta default options.alpha',
    'graph': {
      'inputs': {
        'hardSigmoidInput': {
          'data': [
            -0.05907066911458969, -0.7076089382171631, -0.5228404998779297,
            -0.4231015741825104,  -0.6643692851066589, -0.950294017791748,
            -0.10918906331062317, -0.0129771139472723, -0.4755297303199768,
            -0.5322551727294922,  -0.684307873249054,  -0.4662107527256012,
            -0.3048996329307556,  -0.8025872707366943, -0.2485964000225067,
            -0.663689911365509,   -0.5547611713409424, -0.554258406162262,
            -0.7311381697654724,  -0.4880960285663605, -0.7766845226287842,
            -0.8455570340156555,  -0.555302083492279,  -0.5603444576263428
          ],
          'descriptor': {'dimensions': [1, 2, 3, 4], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'hardSigmoid',
        'arguments': [
          {'input': 'hardSigmoidInput'},
          {'options': {'beta': -0.436186041853034}}
        ],
        'outputs': 'hardSigmoidOutput'
      }],
      'expectedOutputs': {
        'hardSigmoidOutput': {
          'data': [
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
          ],
          'descriptor': {'dimensions': [1, 2, 3, 4], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name':
        'hardSigmoid float32 positive 4D tensor specified all options (positive options.alpha and positive options.beta)',
    'graph': {
      'inputs': {
        'hardSigmoidInput': {
          'data': [
            0.05907066911458969, 0.7076089382171631, 0.5228404998779297,
            0.4231015741825104,  0.6643692851066589, 0.950294017791748,
            0.10918906331062317, 0.0129771139472723, 0.4755297303199768,
            0.5322551727294922,  0.684307873249054,  0.4662107527256012,
            0.3048996329307556,  0.8025872707366943, 0.2485964000225067,
            0.663689911365509,   0.5547611713409424, 0.554258406162262,
            0.7311381697654724,  0.4880960285663605, 0.7766845226287842,
            0.8455570340156555,  0.555302083492279,  0.5603444576263428
          ],
          'descriptor': {'dimensions': [1, 2, 3, 4], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'hardSigmoid',
        'arguments': [
          {'input': 'hardSigmoidInput'},
          {'options': {'alpha': 0.7854232544278235, 'beta': 0.4361860418530341}}
        ],
        'outputs': 'hardSigmoidOutput'
      }],
      'expectedOutputs': {
        'hardSigmoidOutput': {
          'data': [
            0.4825815260410309,
            0.9919585585594177,
            0.8468371629714966,
            0.7684998512268066,
            0.9579971432685852,
            1,
            0.5219456553459167,
            0.44637855887413025,
            0.8096781373023987,
            0.8542316555976868,
            0.9736573696136475,
            0.8023588061332703,
            0.6756613254547119,
            1,
            0.6314394474029541,
            0.9574635624885559,
            0.8719083666801453,
            0.8715134859085083,
            1,
            0.8195480108261108,
            1,
            1,
            0.8723332285881042,
            0.8762935996055603
          ],
          'descriptor': {'dimensions': [1, 2, 3, 4], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name':
        'hardSigmoid float32 positive 4D tensor specified all options (negative options.alpha and negative options.beta)',
    'graph': {
      'inputs': {
        'hardSigmoidInput': {
          'data': [
            0.05907066911458969, 0.7076089382171631, 0.5228404998779297,
            0.4231015741825104,  0.6643692851066589, 0.950294017791748,
            0.10918906331062317, 0.0129771139472723, 0.4755297303199768,
            0.5322551727294922,  0.684307873249054,  0.4662107527256012,
            0.3048996329307556,  0.8025872707366943, 0.2485964000225067,
            0.663689911365509,   0.5547611713409424, 0.554258406162262,
            0.7311381697654724,  0.4880960285663605, 0.7766845226287842,
            0.8455570340156555,  0.555302083492279,  0.5603444576263428
          ],
          'descriptor': {'dimensions': [1, 2, 3, 4], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'hardSigmoid',
        'arguments': [
          {'input': 'hardSigmoidInput'}, {
            'options':
                {'alpha': -0.7854232544278235, 'beta': -0.4361860418530341}
          }
        ],
        'outputs': 'hardSigmoidOutput'
      }],
      'expectedOutputs': {
        'hardSigmoidOutput': {
          'data': [
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
          ],
          'descriptor': {'dimensions': [1, 2, 3, 4], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name':
        'hardSigmoid float32 negative 4D tensor all options (positive options.alpha and negative options.beta)',
    'graph': {
      'inputs': {
        'hardSigmoidInput': {
          'data': [
            -0.05907066911458969, -0.7076089382171631, -0.5228404998779297,
            -0.4231015741825104,  -0.6643692851066589, -0.950294017791748,
            -0.10918906331062317, -0.0129771139472723, -0.4755297303199768,
            -0.5322551727294922,  -0.684307873249054,  -0.4662107527256012,
            -0.3048996329307556,  -0.8025872707366943, -0.2485964000225067,
            -0.663689911365509,   -0.5547611713409424, -0.554258406162262,
            -0.7311381697654724,  -0.4880960285663605, -0.7766845226287842,
            -0.8455570340156555,  -0.555302083492279,  -0.5603444576263428
          ],
          'descriptor': {'dimensions': [1, 2, 3, 4], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'hardSigmoid',
        'arguments': [
          {'input': 'hardSigmoidInput'}, {
            'options':
                {'alpha': 0.7854232544278235, 'beta': -0.4361860418530341}
          }
        ],
        'outputs': 'hardSigmoidOutput'
      }],
      'expectedOutputs': {
        'hardSigmoidOutput': {
          'data': [
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
          ],
          'descriptor': {'dimensions': [1, 2, 3, 4], 'dataType': 'float32'}
        }
      }
    }
  },
  {
    'name':
        'hardSigmoid float32 negative 4D tensor specified all options (negative options.alpha and positive options.beta)',
    'graph': {
      'inputs': {
        'hardSigmoidInput': {
          'data': [
            -0.05907066911458969, -0.7076089382171631, -0.5228404998779297,
            -0.4231015741825104,  -0.6643692851066589, -0.950294017791748,
            -0.10918906331062317, -0.0129771139472723, -0.4755297303199768,
            -0.5322551727294922,  -0.684307873249054,  -0.4662107527256012,
            -0.3048996329307556,  -0.8025872707366943, -0.2485964000225067,
            -0.663689911365509,   -0.5547611713409424, -0.554258406162262,
            -0.7311381697654724,  -0.4880960285663605, -0.7766845226287842,
            -0.8455570340156555,  -0.555302083492279,  -0.5603444576263428
          ],
          'descriptor': {'dimensions': [1, 2, 3, 4], 'dataType': 'float32'}
        }
      },
      'operators': [{
        'name': 'hardSigmoid',
        'arguments': [
          {'input': 'hardSigmoidInput'}, {
            'options':
                {'alpha': -0.7854232544278235, 'beta': 0.4361860418530341}
          }
        ],
        'outputs': 'hardSigmoidOutput'
      }],
      'expectedOutputs': {
        'hardSigmoidOutput': {
          'data': [
            0.4825815260410309,
            0.9919585585594177,
            0.8468371629714966,
            0.7684998512268066,
            0.9579971432685852,
            1,
            0.5219456553459167,
            0.44637855887413025,
            0.8096781373023987,
            0.8542316555976868,
            0.9736573696136475,
            0.8023588061332703,
            0.6756613254547119,
            1,
            0.6314394474029541,
            0.9574635624885559,
            0.8719083666801453,
            0.8715134859085083,
            1,
            0.8195480108261108,
            1,
            1,
            0.8723332285881042,
            0.8762935996055603
          ],
          'descriptor': {'dimensions': [1, 2, 3, 4], 'dataType': 'float32'}
        }
      }
    }
  }
];

if (navigator.ml) {
  hardSigmoidTests.forEach((test) => {
    webnn_conformance_test(
        buildGraphAndCompute, getHardSigmoidPrecisionTolerance, test);
  });
} else {
  test(() => assert_implements(navigator.ml, 'missing navigator.ml'));
}
